<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>材料采购质检总报表页面</title>
<link rel="stylesheet" href="../../layui/css/layui.css" media="all">
<style type="text/css">
body {
	margin: 20px 0px;
}
 body{margin: 10px;}
    .demo-carousel{height: 300px; line-height: 300px; text-align: center;}
    .demoTable{
    	z-index: 10px;
    }
</style>
</head>
<body>
	<table class="layui-hide" id="qtSumModel" lay-filter="demo"></table>
</div>

<script type="text/html" id="barDemo">
{{# if(d.sumRemark == '未质检'){ }}  
	<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">立即质检</a>
{{# }else{ }}
	<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看质检详情</a>
	{{# if(d.sumRemark == '已入库'){ }}
  		<a class="layui-btn layui-btn-xs" lay-event="">已入库</a>
	{{# }else{ }}
		<a class="layui-btn layui-btn-xs" lay-event="rk">入库</a>
	{{# } }}
{{# }}}
</script>
	<script type="text/javascript" src="../../res/js/base.js"></script>
	<script src="../../layui/layui.js"></script>
<script>

layui.use(['laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function(){
	  var laydate = layui.laydate //日期
	  ,laypage = layui.laypage //分页
	  layer = layui.layer //弹层
	  ,table = layui.table //表格
	  ,upload = layui.upload //上传
	  ,element = layui.element; //元素操作
	 
	  
	  //日期
	  laydate.render({
		    elem: '#date',
		    type:'datetime'
	  });
	  laydate.render({
		    elem: '#date1',
		    type:'datetime'
	  });
	  
	  //监听Tab切换
	  element.on('tab(demo)', function(data){
	    layer.msg('切换了：'+ this.innerHTML);
	    console.log(data);
	  });
	  
	  //执行一个 table 实例
	  table.render({
	     elem: '#qtSumModel'
	    ,width:1000
	    ,height: 500
	    ,url: getRootPath()+'qtSumModel/findAll.action?condition=metails' //数据接口
	    ,page: true //开启分页
	    ,method:'post'
	    ,cols: [[ //表头
	       {type:'checkbox', fixed: 'left'}
	      ,{field: 'sumId', title: '质检总报表ID', width:120, fixed: 'left'}
	      ,{field: 'poId', title: '分店采购订单ID', width:120}
	      ,{field: 'sumNopass', title: '质检总未通过数', width:120}
	      ,{field: 'sumSumnum', title: '质检总数', width:120}
	      ,{field: 'sumRate', title: '质检总通过率', width: 120}
	      ,{field: 'sumTimes', title: '质检总报表时间', width: 120}
	  	  ,{field: 'filName', title: '分公司名称', width: 120}
	      ,{fixed: 'right',title: '操作', width: 185, align:'center', toolbar: '#barDemo'}
	    ]]
	  	,id: 'testReload'
	  });
	  
	  //监听工具条
	  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
	    var data = obj.data //获得当前行数据
	    ,layEvent = obj.event; //获得 lay-event 对应的值
	    if(layEvent === 'rk'){
	    	 
	    	// alert("您点击了入库按钮");
	    	 var sumId = data.sumId;
	    	 var poId = data.poId;
	    	 var filId = data.filId;
	    	 layer.confirm('确认入库?', function(index){
		    	 layer.close(index);
			      
			      //使用jquery的ajax方式向后台提交数据
				  var url = "../../Repertory/insertById.action";
				  
			 	  var data = {"sumId":sumId,"poId":poId,"filId":filId};
				  $.post(url,data,function(data){
					 // alert(data);
						 if(data =="ok"){
							 
							layer.msg('入库成功', {
								  icon: 1,
								  time: 1000 //1秒关闭（如果不配置，默认是3秒）
								}, function(){
									
								  location.reload(); // 页面刷新
									 
							});
							$("#rk").attr("style","display:none");
						}else {
							layer.msg('入库失败',{
									icon:2,
									time: 1000
								},function(){
									location.reload();
							})
						}
						  

					}); 
		    });
	    	/*  var sumId=data.sumId;
	    	 var filId=data.filId;
	    	 var sumNopass=data.sumNopass;
	    	 var sumSumnum=data.sumSumnum;
	    	 var poId=data.poId;
	    	 
	    	 layer.confirm('确认入库?', function(index){
	    	 layer.close(index);
		      
		      //使用jquery的ajax方式向后台提交数据
			  var url = "../../Repertory/insertById.action";
			  
		 	  var data = {sumId:sumId,filId:filId,sumNopass:sumNopass,sumSumnum:sumSumnum,poId:poId};
			  $.post(url,data,function(data){
				  
					 if(data =="ok"){
						 
						layer.msg('入库成功', {
							  icon: 1,
							  time: 1000 //1秒关闭（如果不配置，默认是3秒）
							}, function(){
								
							  location.reload(); // 页面刷新
								 
						});
						$("#rk").text("已入库");
					}else {
						layer.msg('入库失败',{
								icon:2,
								time: 1000
							},function(){
								location.reload();
						})
					}
					  

				}); 
	    }); */
	      
	      
	    } else if(layEvent === 'detail'){
	    	var sumId=data.sumId;
	    	var sumRemark = data.sumRemark;
	    	var num = 0;
			if(sumRemark == "已质检" || sumRemark == "已入库"){
				num = 1;
			}
	    	var condition = "materials";
   	    	layer.open({
   	 			  type: 2,
   	 			  area : ['76%' , '75%'],//弹出框大小
   	 			  shift:1,//弹出框动画效果
   	 			  content: 'QualityTestingModelShowList.html?num='+num+"&sumId="+sumId+"&condition="+condition //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
	   	 	});
		}
	  });
	  
	  
	  
	  

	//条件查询
		var $ = layui.$;

		$('.demoTable .layui-btn').on('click', function() {
			//var demoReload = $('#demoReload');
			//alert($("#date").val());
			//执行重载
			table.reload('testReload', {
				page : {
					curr : 1
				//重新从第 1页开始
				},
				where : {
					//sellName : demoReload.val(),
					dateOne: $("#date").val(),
					dateTwo: $("#date1").val()
				}
				
			});
		});
});
			  
	/*  $('#qtSumModelAdd').on('click', function(){
		 layer.open({
			  type: 	2,
			  area : ['60%' , '80%'],//弹出框大小
			  shift:1,//弹出框动画效果
			  content: ['QtSumModelAdd.html','on'] //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
			}); 
	   }); 
	  
	});*/
	  
	  
</script>


</body>
</html>